home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / tde40.zip / criterr.c < prev    next >
C/C++ Source or Header  |  1994-06-05  |  15KB  |  484 lines

  1. /*
  2.  * I haven't tested the signals in UNIX, yet..., Frank.
  3.  *
  4.  * Instead of the Abort, Retry, Ignore thing, let's try to handle critical
  5.  * errors within tde.  Give the user some indication of the critical error
  6.  * and then find out what the user wants to do.
  7.  *
  8.  * If we are in a unix environment, lets map signals to our DOS critical
  9.  * error handler.
  10.  *
  11.  * IMPORTANT:  This is a replacement for the standard DOS critical error
  12.  * handler.  Since DOS is not re-entrant, do not call any functions that,
  13.  * directly or indirectly, call DOS functions.  We are in some DOS function
  14.  * when a critical error occurs.  Using BIOS and direct hardware I/O
  15.  * functions, however, is allowed.
  16.  *
  17.  * The prototype for the critical error handler is
  18.  *
  19.  *            int  FAR crit_err_handler( void )
  20.  *
  21.  * The handler is explicitly declared as "FAR", because the assembly
  22.  * routine is hard coded for a "FAR" function.  See the bottom of
  23.  * int24.asm for more info.
  24.  *
  25.  * See (incidentally, these are the current references for MSDOS 6.0):
  26.  *
  27.  *   Microsoft Knowledge Base, "Action Taken on Abort, Retry, Ignore, Fail",
  28.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q67586,
  29.  *    Publication Date:  March 24, 1993.
  30.  *
  31.  *   Microsoft Knowledge Base, "Extended Error Code Information",
  32.  *    Microsoft Corporation, Redmond, Wash., 1992, Document Number: Q74463,
  33.  *    Publication Date:  March 24, 1993.
  34.  *
  35.  *   Programmer's Reference Manual, Microsoft Corporation, Redmond,
  36.  *    Washington, 1986, Document No. 410630014-320-003-1285, pp. 1-20 thru
  37.  *    1-21, pp. 1-34 thru 1-38, p 1-99, pp. 1-121 thru 1-124, pp. 1-216 thru
  38.  *    1-218, pp. 2-1 thru 2-30.
  39.  *
  40.  *   Ray Duncan, _Advanced MS-DOS_, Microsoft Press, Redmond, Washington,
  41.  *    1986, ISBN 0-914845-77-2, pp 89-97, pp 130-133.
  42.  *
  43.  *
  44.  * New editor name:  TDE, the Thomson-Davis Editor.
  45.  * Author:           Frank Davis
  46.  * Date:             June 5, 1991, version 1.0
  47.  * Date:             July 29, 1991, version 1.1
  48.  * Date:             October 5, 1991, version 1.2
  49.  * Date:             January 20, 1992, version 1.3
  50.  * Date:             February 17, 1992, version 1.4
  51.  * Date:             April 1, 1992, version 1.5
  52.  * Date:             June 5, 1992, version 2.0
  53.  * Date:             October 31, 1992, version 2.1
  54.  * Date:             April 1, 1993, version 2.2
  55.  * Date:             June 5, 1993, version 3.0
  56.  * Date:             August 29, 1993, version 3.1
  57.  * Date:             November 13, 1993, version 3.2
  58.  * Date:             June 5, 1994, version 4.0
  59.  *
  60.  * This code is released into the public domain, Frank Davis.
  61.  *    You may distribute it freely.
  62.  */
  63.  
  64. #include "tdestr.h"
  65. #include "common.h"
  66. #include "tdefunc.h"
  67. #include "criterr.h"
  68.  
  69. #if defined( __UNIX__ )
  70.  #include <signal.h>
  71. #endif
  72.  
  73. /*
  74.  * Save the area of the screen that will display the Critical
  75.  * Error info.  CEH_WIDTH and CEH_HEIGHT are the dimensions of critical
  76.  * error screen in criterr.h.   CEH_OFFSET is the offset into the screen
  77.  * refresh buffer.  Let the compiler calculate the offset, 'cause the offset
  78.  * don't change anyway.
  79.  */
  80. #define CEH_ROW         5
  81. #define CEH_COL         6
  82. #define CEH_WIDTH       69
  83. #define CEH_HEIGHT      15
  84.  
  85. #define CEH_OFFSET      ((CEH_ROW * 160) + (CEH_COL * 2))
  86.  
  87. #define NEXT_LINE       160
  88.  
  89.  
  90. #if defined( __UNIX__ )
  91. /*
  92.  **********************************************************************
  93.  ******************************  PART 1  ******************************
  94.  **********************************************************************
  95.  *
  96.  * Let's try to make unix have the look and feel of a PC.
  97.  */
  98.  
  99. /*
  100.  * buffer for ceh info screen.  make this a chtype array
  101.  */
  102. chtype ceh_buffer[CEH_HEIGHT][CEH_WIDTH];   /* chtype is defined in curses.h */
  103.  
  104. /*
  105.  * Name:    crit_err_handler
  106.  * Purpose: Show user something is wrong and get a response
  107.  * Date:    November 13, 1993
  108.  * Notes:   I noticed that some signals in Linux
  109.  */
  110. void  crit_err_handler( int sig )
  111. {
  112. int  attr;
  113. int  rc;
  114. int  c;
  115. int  action;
  116.  
  117.    attr = g_display.help_color;
  118.    save_area( (chtype *)ceh_buffer );
  119.    show_error_screen( CEH_ROW, CEH_COL );
  120.    switch (sig) {
  121.       case SIGABRT :
  122.          s_output( sigabrt_1,  8, 23, attr );
  123.          s_output( sigabrt_2,  9, 23, attr );
  124.          s_output( sigabrt_3, 10, 23, attr );
  125.          break;
  126.       case SIGALRM :
  127.          s_output( sigalrm_1,  8, 23, attr );
  128.          s_output( sigalrm_2,  9, 23, attr );
  129.          break;
  130.       case SIGCHLD :
  131.          s_output( sigchld_1,  8, 23, attr );
  132.          s_output( sigchld_2,  9, 23, attr );
  133.          s_output( sigchld_3, 10, 23, attr );
  134.          s_output( sigchld_4, 11, 23, attr );
  135.          break;
  136.       case SIGCONT :
  137.          s_output( sigcont_1,  8, 23, attr );
  138.          s_output( sigcont_2,  9, 23, attr );
  139.          s_output( sigcont_3, 10, 23, attr );
  140.          s_output( sigcont_4, 11, 23, attr );
  141.          break;
  142.       case SIGFPE :
  143.          s_output( sigfpe_1,  8, 23, attr );
  144.          s_output( sigfpe_2,  9, 23, attr );
  145.          s_output( sigfpe_3, 10, 23, attr );
  146.          break;
  147.       case SIGHUP :
  148.          s_output( sighup_1,  8, 23, attr );
  149.          s_output( sighup_2,  9, 23, attr );
  150.          s_output( sighup_3, 10, 23, attr );
  151.          break;
  152.       case SIGILL :
  153.          s_output( sigill_1,  8, 23, attr );
  154.          s_output( sigill_2,  9, 23, attr );
  155.          s_output( sigill_3, 10, 23, attr );
  156.          break;
  157.       case SIGINT :
  158.          s_output( sigint_1,  8, 23, attr );
  159.          s_output( sigint_2,  9, 23, attr );
  160.          s_output( sigint_3, 10, 23, attr );
  161.          break;
  162.       case SIGIO :
  163.          s_output( sigio_1,  8, 23, attr );
  164.          s_output( sigio_2,  9, 23, attr );
  165.          s_output( sigio_3, 10, 23, attr );
  166.          break;
  167. /*
  168.  * SIGIOT and SIGABRT share same signal in linux????, Frank
  169.  *
  170.       case SIGIOT :
  171.          s_output( sigiot_1,  8, 23, attr );
  172.          s_output( sigiot_2,  9, 23, attr );
  173.          s_output( sigiot_3, 10, 23, attr );
  174.          break;
  175. */
  176.       case SIGKILL :
  177.          s_output( sigkill_1,  8, 23, attr );
  178.          s_output( sigkill_2,  9, 23, attr );
  179.          s_output( sigkill_3, 10, 23, attr );
  180.          break;
  181.       case SIGPIPE :
  182.          s_output( sigpipe_1,  8, 23, attr );
  183.          s_output( sigpipe_2,  9, 23, attr );
  184.          s_output( sigpipe_3, 10, 23, attr );
  185.          break;
  186. /*
  187.  * SIGPOLL, SIGIO, and SIGURG share the same signal in linux???, Frank
  188.  *
  189.       case SIGPOLL :
  190.          s_output( sigpoll_1,  8, 23, attr );
  191.          s_output( sigpoll_2,  9, 23, attr );
  192.          break;
  193.  */
  194.       /*
  195.        * is TDE supposed to catch profiler signals?
  196.       case SIGPROF :
  197.          break;
  198.       */
  199.       case SIGPWR :
  200.          s_output( sigpwr_1,  8, 23, attr );
  201.          s_output( sigpwr_2,  9, 23, attr );
  202.          s_output( sigpwr_3, 10, 23, attr );
  203.          break;
  204.       case SIGQUIT :
  205.          s_output( sigquit_1,  8, 23, attr );
  206.          s_output( sigquit_2,  9, 23, attr );
  207.          s_output( sigquit_3, 10, 23, attr );
  208.          break;
  209.       case SIGSEGV :
  210.          s_output( sigsegv_1,  8, 23, attr );
  211.          s_output( sigsegv_2,  9, 23, attr );
  212.          s_output( sigsegv_3, 10, 23, attr );
  213.          break;
  214.       case SIGSTOP :
  215.          s_output( sigstop_1,  8, 23, attr );
  216.          s_output( sigstop_2,  9, 23, attr );
  217.          s_output( sigstop_3, 10, 23, attr );
  218.          break;
  219.       case SIGTERM :
  220.          s_output( sigterm_1,  8, 23, attr );
  221.          s_output( sigterm_2,  9, 23, attr );
  222.          s_output( sigterm_3, 10, 23, attr );
  223.          break;
  224.       case SIGTRAP :
  225.          s_output( sigtrap_1,  8, 23, attr );
  226.          s_output( sigtrap_2,  9, 23, attr );
  227.          s_output( sigtrap_3, 10, 23, attr );
  228.          break;
  229.       case SIGTSTP :
  230.          s_output( sigtstp_1,  8, 23, attr );
  231.          s_output( sigtstp_2,  9, 23, attr );
  232.          s_output( sigtstp_3, 10, 23, attr );
  233.          break;
  234.       case SIGTTIN :
  235.          s_output( sigttin_1,  8, 23, attr );
  236.          s_output( sigttin_2,  9, 23, attr );
  237.